package com.youlu.campus.admin.card.controller;

import com.youlu.campus.admin.card.dto.*;
import com.youlu.campus.admin.card.service.CardGoodsService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : [dengbo]
 * @className : CardGoodsController
 * @description : [会员卡商品，卡商品类]
 * @createTime : [2022/12/16 21:44]
 */
@Slf4j
@RestController
@RequestMapping("/ts-card/")
public class CardGoodsController {
    @Autowired
    private CardGoodsService cardGoodsService;

    /**
     * 商品保存
     * 会员卡商品保存
     * @param dto 商品保存
     * @return
     */
    @PostMapping("/goods/save")
    public QResult save(@Validated @RequestBody CardGoodsSaveDTO dto) {
        return QResult.success(cardGoodsService.save(dto));
    }

    /**
     * 商品列表
     * 会员卡商品列表
     * @param searchDto 商品列表
     * @return
     */
    @PostMapping("/goods/list")
    public QResult list(@RequestBody CardGoodsSearchDTO searchDto) {
        return QResult.success(cardGoodsService.list(searchDto));
    }

    /**
     * 商品删除
     * 会员卡商品删除
     * @param searchDto 商品删除
     * @return
     */
    @PostMapping("/goods/delete")
    public QResult delete(@Validated @RequestBody CardGoodsDeleteDTO searchDto) {
        return QResult.success(cardGoodsService.delete(searchDto));
    }


    /**
     * 商品上下架
     * 会员卡商品上下架
     * @param dto 商品上下架
     * @return
     */
    @PostMapping("/goods/onsale")
    public QResult onSale(@Validated @RequestBody CardGoodsDeleteDTO dto) {
        return QResult.success(cardGoodsService.onsale(dto));
    }

    /**
     * 商品价格同步
     * 会员卡商品价格同步
     * @param dto 商品价格同步
     * @return
     */
    @PostMapping("/goods/price/sync")
    public QResult goodsPirceSync(@Validated @RequestBody CardGoodsSyncDTO dto) {
        return QResult.success(cardGoodsService.syncGoodsPrice(dto));
    }
}